﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NRCP.BusinessEntities;

namespace NRCP.BusinessLogicLayer
{
    public partial class NationalPlanDivisionBLL
    {
        public List<TempValueObject> GetNationalPlanDivisionsId(int nationalPlanId)
        {
            var result = from nationalPlanDivision in _socialShareDatabaseContext.NationalPlanDivisions
                         where nationalPlanId == null ? nationalPlanDivision.NationalPlanId == null : nationalPlanDivision.NationalPlanId == nationalPlanId
                         select new { Id = nationalPlanDivision.Id, Total = nationalPlanDivision.Division.Name };

            List<TempValueObject> tmpVal = result.ToList().ConvertAll(x => new TempValueObject { Key = x.Id.ToString(), Value = x.Total.ToString() });

            return tmpVal;
        }

        public NationalPlanDivision GetNationalPlanDivision(Func<NationalPlanDivision, bool> query)
        {
            try
            {
                //CustomerContent
                NationalPlanDivision result = _socialShareDatabaseContext.NationalPlanDivisions.FirstOrDefault(query);
                return result;
            }
            //handling other exceptions...
            catch (Exception ex)
            {
                //Error handling
                throw ex;
            }            
        }
    }
}